//
//  CommonNewsCell.m
//  SportSocial
//
//  Created by yull on 14/12/21.
//  Copyright (c) 2014年 yull. All rights reserved.
//

#import "CommonNewsCell.h"
#import "UIImageView+WebCache.h"

@implementation CommonNewsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        CGRect rect = CGRectMake(10, 10, 80, 60);
        self.newsImageView = [[UIImageView alloc] initWithFrame:rect];
        [self.contentView addSubview:self.newsImageView];
        
        rect.origin.x = self.newsImageView.right + 10;
        rect.size.width = self.contentView.width - rect.origin.x - 10;
        rect.size.height = 20;
        self.newsTitleLabel = [[UILabel alloc] initWithFrame:rect];
        self.newsTitleLabel.backgroundColor = [UIColor clearColor];
        self.newsTitleLabel.textColor = [UIColor blackColor];
        self.newsTitleLabel.font = [UIFont systemFontOfSize:14.0f];
        self.newsTitleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        [self.contentView addSubview:self.newsTitleLabel];
        
        rect.origin.y = self.newsTitleLabel.bottom;
        rect.size.height = self.newsImageView.height - self.newsTitleLabel.height;
        self.newsDetailLabel = [[UILabel alloc] initWithFrame:rect];
        self.newsDetailLabel.backgroundColor = [UIColor clearColor];
        self.newsDetailLabel.textColor = [UIColor grayColor];
        self.newsDetailLabel.font = [UIFont systemFontOfSize:13.0f];
        self.newsDetailLabel.numberOfLines = 2;
        self.newsDetailLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        [self.contentView addSubview:self.newsDetailLabel];
    }
    return self;
}

+ (CGFloat)defaultCommonNewsCellHeight
{
    return 80.0f;
}

- (void)drawCellWithNewsModel:(NewsModel *)newsModel
{
    [self.newsImageView sd_setImageWithURL:[NSURL URLWithString:newsModel.img]];
    
    self.newsTitleLabel.text = newsModel.title;
    
    self.newsDetailLabel.text = newsModel.brief;
}

- (UIEdgeInsets)layoutMargins
{
    return UIEdgeInsetsZero;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
